#ifndef NODE_H
#define NODE_H
#include <QList>
#include <QFileInfo>
#include <QStringList>
#include <QMetaType>

enum NodeTypes{
    SimpleType,
    FileType,
    SpecType,
    DirectoryType,
    PyModuleType,
    DesignerType,
    ResourcesType
};

namespace Plugins {
    class Project;
}

class Node: public QObject
{
    Q_OBJECT
friend class ProjectTreeModel;
public:
    Node();
    Node(const Node &node);
    Node(const QFileInfo & info, const QString & spec = "", NodeTypes type = SimpleType);
    Node(const QString & path, const QString & spec = "", NodeTypes type = SimpleType);
    virtual ~Node();

    void init();
    int calcPosition(Node *node);
    void addNode(Node* node);
    int row();
    QString path();
    QString parentPath();
    QString name();
    QString dirName();
    QString baseName();
    NodeTypes nodeType();
    QString extension();
    QFileInfo fileInfo();
    bool isModified();
    void setModified(bool modified);
    QString spec();

    void reparent(Node * newParent);
    void checkExistingChildren(const QStringList & extFilter);
    void changeType(NodeTypes newType);
signals:
    void nodeToDestroy(QList<Node*>);
private:
    QFileInfo    _info;
    Node*        _parent;
    QString      _spec;
    bool         _modified;
    QString      _path;
    NodeTypes    _type;
    QList<Node*> _children;
};

Q_DECLARE_METATYPE(Node*)

/*
class DirectoryNode: public Node
{
public:
    DirectoryNode(const QString & path):Node(path){}
    DirectoryNode(const QFileInfo & info):Node(info){}
    virtual NodeTypes nodeType()
    {
        return DirectoryType;
    }
};

class FileNode: public Node
{
public:
    FileNode(const QString & path):Node(path){}
    FileNode(const QFileInfo & info):Node(info){}

    QString extension()
    {
        return name().split(".").last();
    }
    virtual NodeTypes nodeType()
    {
        return FileType;
    }
};

class DesignerNode: public Node
{
public:
    DesignerNode(const QString & path):Node(path, "designer"){}
    DesignerNode(const QFileInfo & info):Node(info, "designer"){}
    virtual NodeTypes nodeType()
    {
        return SpecType;
    }
};

class ResourceNode: public Node
{
public:
    ResourceNode(const QString & path):Node(path, "resource"){}
    ResourceNode(const QFileInfo & info):Node(info, "resource"){}
    virtual NodeTypes nodeType()
    {
        return SpecType;
    }
};

class PyModuleNode: public Node
{
public:
    PyModuleNode(const QString & path):Node(path){}
    PyModuleNode(const QFileInfo & info):Node(info){}
    virtual NodeTypes nodeType()
    {
        return PyModuleType;
    }
};
*/

void removeNode(const QString & path);
Node * findNode(const QString & path);

#endif // NODE_H
